package com.cloud.common.utils;

import com.cloud.common.constants.GlobalConstants;
import com.cloud.service.RedisService;
import com.cloud.system.entity.SysDictData;
import com.cloud.utils.SpringUtils;

import java.util.List;

/**
 * 字典工具类
 *
 * @author zx
 */
public class DictUtils {

    /**
     * 设置字典缓存
     *
     * @param key          参数键
     * @param dictDataList 字典数据列表
     */
    public static void setDictCache(String key, List<SysDictData> dictDataList) {
        SpringUtils.getBean(RedisService.class).setHash(GlobalConstants.sysDictInfo, key, dictDataList);
    }

    /**
     * 获取字典缓存
     *
     * @param key 参数键
     */
    public static List<SysDictData> getDictCache(String key) {
        return SpringUtils.getBean(RedisService.class).getHashKey(GlobalConstants.sysDictInfo, key);
    }

    /**
     * 根据字典类型删除缓存
     *
     * @param key 参数键
     */
    public static void deleteDictData(String key) {
        SpringUtils.getBean(RedisService.class).delHashKey(GlobalConstants.sysDictInfo, key);
    }

    /**
     * 清空字典缓存
     */
    public static void clearDictCache() {
        SpringUtils.getBean(RedisService.class).del(GlobalConstants.sysDictInfo);
    }

}
